home *** CD-ROM | disk | FTP | other *** search
/ Programmers Heaven 2 / Programmers Heaven 2.iso / files / graphics / library / wgt51_r2.zip / WGT5 / EXAMPLES / WGT23.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-03  |  4.3 KB  |  117 lines

  1. /*
  2. ==============================================================================
  3.                       WordUp Graphics Toolkit Version 5.0                     
  4.                              Demonstration Program 23                         
  5.                                                                               
  6.  Makes a large 256 color, animating mouse cursor!                            
  7.                                                                               
  8.  *** PROJECT ***                                                             
  9.  This program requires the files WSPR_WC.LIB and WGT5_WC.LIB to be linked.   
  10.                                                                               
  11.  *** DATA FILES ***                                                          
  12.  Make sure that MOUSE.SPR is in your executable directory.                   
  13.                                                            WATCOM C++ VERSION 
  14. ==============================================================================
  15. */
  16.  
  17. #include <stdio.h>
  18. #include <dos.h>
  19. #include <conio.h>
  20. #include <stdlib.h>
  21. #include <malloc.h>
  22. #include <wgt5.h>
  23. #include <wgtspr.h>
  24.  
  25. #define SPRITES 20                    // We're loading 20 sprites
  26.  
  27. short i;                              // Generic counter
  28. color palette[256];                   // Our palette
  29. block sprites[21];                    // Pointers to sprites
  30. short quit;                           // if quit !=0, program quits
  31. short oldmode;                        // Stores initial video mode
  32.  
  33.  
  34. void looper(void);                    // Function to move cursor
  35.  
  36.  
  37. void main(void)
  38. {
  39.   if ( !vgadetected () )
  40.   {
  41.     printf("Error - VGA card required for any WGT program.\n");
  42.     exit (0);
  43.   }
  44.   printf ("WGT Example #23\n\n");
  45.   printf ("Many times you will find the need to use a 256 color mouse cursor.\n");
  46.   printf ("This program replaces the standard arrow with an animating image\n");
  47.   printf ("(which is simply a bitmap displayed at the mouse coordinates).\n");
  48.   printf ("This technique must be used in SVGA when the mouse driver doesn't\n");
  49.   printf ("support higher resolutions (the coords must be scaled as well).\n");
  50.   printf ("A keypress ends the demo\n");
  51.   printf ("\n\nPress any key to continue.\n");
  52.   getch ();
  53.  
  54.   oldmode = wgetmode ();
  55.   vga256 ();
  56.  
  57.   /* Load our sprites from the file. Palette is loaded too */
  58.   wloadsprites (palette, "mouse.spr", sprites, 0, 20);
  59.   wsetpalette (0, 255, palette);
  60.  
  61.   /* Initialize the WGT sprite system */
  62.   initialize_sprites (sprites);
  63.   maxsprite = 1;                       /* number of sprites on */
  64.  
  65.   minit ();                      /* initialize mouse */
  66.  
  67.   for (i = 0; i < 200; i++)         /* draw a background */
  68.   {
  69.     wsetcolor (i);
  70.     wline (0, i, 159, i);
  71.     wline (160, 199 - i, 319, 199 - i);
  72.   }
  73.  
  74.   wcopyscreen (0, 0, 319, 199, NULL, 0, 0, spritescreen);
  75.   wcopyscreen (0, 0, 319, 199, NULL, 0, 0, backgroundscreen);
  76.   /* when using sprites, whatever is on the visual page must be on
  77.      spritescreen and backgroundscreen too! */
  78.  
  79.   /* Also, you must make sure you turn a sprite on AFTER you draw
  80.      the background or it will leave a black spot where the sprite
  81.      is first shown. */
  82.   spriteon (0, 160, 100, 1);                /* turn on any sprites */
  83.  
  84.   animate (0, "(1,30)(2,30)(3,30)(4,30)(3,30)(2,30)R");
  85.   animon (0);
  86.   /* animate the sprite */
  87.  
  88.   do {
  89.     looper ();           /* Position cursor where mouse is */
  90.   } while (!quit);
  91.   getch ();
  92.  
  93.   spriteoff (0);                         /* turn off sprites */
  94.   /* To be safe, turn off all sprites before ending your program.
  95.      This will free any memory used from them. */
  96.  
  97.   deinitialize_sprites ();
  98.   mdeinit ();                            /* Deinitialize the mouse handler */
  99.   wfreesprites (sprites, 0, 20);         /* free memory */
  100.   wsetmode (oldmode);                    /* restore old video mode */
  101. }
  102.  
  103.  
  104. void looper(void)
  105. {
  106.   erase_sprites ();                /* clear the sprites */
  107.  
  108.   s[0].x = mouse.mx;               /* any direct sprite movements must be placed */
  109.   s[0].y = mouse.my;               /* between erasespr and drawspr */
  110.   /* This will place sprite number 1 where the mouse cursor is. */
  111.  
  112.   wretrace ();
  113.   draw_sprites (1);               /* draw them back on */
  114.   if (kbhit ()) 
  115.     quit = 1;
  116. }
  117.